<template>
  <div class="goods-block">
    <van-cell :title="title" :icon="icon"></van-cell>
    <van-row type="flex" justify="center">
      <van-col span="7" class="goods_item" v-for="(item,i) in productList" :key="i" @click="onDetail(item)">
        <div class="goods-card">
          <van-image :src="APIDomainName + item.pic" class="goods-image"></van-image>
          <div class="goods-content">
            <div class="van-ellipsis goods-title">{{item.title}}</div>
            <div class="price">{{item.discount ? `￥${item.discount}` : '￥' + item.price}}</div>
            <div v-if="item.discount" class="original-price">￥{{item.price}}</div>
          </div>
        </div>
      </van-col>
    </van-row>
  </div>
</template>

<script>
export default {
  name: "homeProduct",
  props: {
    title: {
      type: String,
      default: "商品",
    },
    icon: {
      type: String,
      default: null,
    },
    productList: {
      type: Array,
      default: () => []
    }
  },
  methods: {
    onDetail(item) {
      this.$router.push({ name: 'productDetail', query: { id: item.product_id } })
    }
  }
}
</script>

<style lang="less" scoped>
// 粉色系变量
@bgColor: #FFF5F7;           // 页面背景
@headerBg: #FFE4E9;         // 标题背景
@cardBg: #FFFFFF;           // 卡片背景
@mainColor: #FF69B4;        // 主色调
@priceColor: #FF4D92;       // 价格颜色
@textPrimary: #333333;      // 主要文字
@textSecondary: #666666;    // 次要文字
@hoverBgColor: #FFEBF2;     // 鼠标悬停时卡片背景色
@borderColor: #FFE4E9;      // 卡片边框颜色

.goods-block {
  background-color: @bgColor;
  padding: 10px;

  .van-cell {
    font-size: 16px;
    background-color: @headerBg;
    color: @textPrimary;
    font-weight: 500;
    padding: 12px 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(255, 105, 180, 0.1);
    margin-bottom: 15px;

    // 图标颜色
    .van-cell__icon {
      color: @mainColor;
      font-size: 20px;
    }
  }

  .goods_item {
    display: flex;
    flex-direction: column;
    margin: 10px 8px;
    transition: all 0.3s ease;

    .goods-card {
      background-color: @cardBg;
      border: 1px solid @borderColor;
      border-radius: 12px;
      overflow: hidden;
      box-shadow: 0 4px 12px rgba(255, 105, 180, 0.1);

      &:hover {
        background-color: @hoverBgColor;
        border-color: @mainColor;
        box-shadow: 0 6px 16px rgba(255, 105, 180, 0.2);
      }

      .goods-image {
        width: 100%;
        height: 160px;
        object-fit: cover;
        transition: transform 0.3s ease;

        &:hover {
          transform: scale(1.05);
        }
      }

      .goods-content {
        padding: 12px 15px;

        .goods-title {
          color: @textPrimary;
          font-size: 16px;
          font-weight: 500;
          margin-bottom: 8px;
        }

        .price {
          font-size: 18px;
          color: @priceColor;
          font-weight: bold;
          margin-bottom: 4px;
        }

        .original-price {
          font-size: 14px;
          color: @textSecondary;
          text-decoration: line-through;
        }
      }
    }
  }
}
</style>